import { defineStore } from 'pinia';
import { switchLanguage } from '@/i18n';

const defaultLanguage = localStorage.getItem('language') || 'zh';

export const useI18nStore = defineStore('i18n', {
  state: () => {
    return { translate: switchLanguage(defaultLanguage) };
  },

  actions: {
    chooseLanguage(lang) {
      localStorage.setItem('language', lang);
      this.translate = switchLanguage(lang);
    }
  }
});
